<?php
$SITEROOT = '../';
include_once($SITEROOT . 'assets/snippets/shoppingCart/dbconfig.inc.php');
include_once($SITEROOT . 'assets/snippets/shoppingCart/kiwee.class.php');

$kiwee = new Kiwee();

if(IN_MANAGER_MODE!="true") die('<b>' . $_lang['kiwee_include_order_error'] . '</b>');
if ($_SESSION['mgrPermissions']['settings'] != "1") { echo 'Insufficient permissions for this module.'; exit; }

$theme = $manager_theme ? "$manager_theme/":"";
$modx->manager->initPageViewState();
?>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/modal_window/javascripts/modal.js"></script>
<script type="text/javascript" src="actions/includes/interface.js"></script>
<link href="js/modal_window/stylesheets/modal.css" rel="stylesheet" type="text/css" />
<link href="actions/includes/kiwee.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
	function tax_add() {
		var poststr = "trxntype=tax_add&postalcode=" + urival('postalcode') + "&description=" + urival('description') +
					  "&rate=" + urival('rate');
		makePOSTRequest('actions/ajax.php', poststr, 'tax_gridreload');
	}
	
	function tax_delete(id){
		if (confirm("Are you sure you want to delete this tax rate?") == true) {
			makePOSTRequest('actions/ajax.php', "trxntype=tax_delete&id=" + id, 'tax_gridreload');
		}
	}
	
	function tax_gridload(){
		makePOSTRequest('actions/ajax.php', "trxntype=tax_gridload", 'tax_gridload');
	}
	
	function tax_properties(id) {
		makePOSTRequest('actions/ajax.php', "trxntype=tax_properties&id=" + id, 'tax_properties');
	}
	
	function tax_update(id){
	   var poststr = "trxntype=tax_update&id=" + id + "&postalcode=" + urival('upostalcode') + "&description=" +
					 urival('udesc') + "&rate=" + urival('urate');
	   makePOSTRequest('actions/ajax.php', poststr, 'tax_gridreload');
	   hideBox();
	}
	
	function ajaxrendercomponent(name) {
        if (http_request.responseText.substring(0, 5) == "ERROR") {
            alert(http_request.responseText);
		} else if (name == 'tax_gridload') {
		   document.getElementById('tax_grid').innerHTML=http_request.responseText;
		} else if (name == 'tax_gridreload') {
			tax_gridload();
		} else if (name == 'tax_properties') {
			document.getElementById('inner-box').innerHTML=http_request.responseText;
			showBox();
		} else {			
			alert(name + ": " + http_request.responseText);
		}
	}
	tax_gridload();
</script>

<div id="overlay" onclick="hideBox()" style="display:none"></div>
<div id="box" style="display:none">
    <img id="close" src="js/modal_window/images/close.gif" onclick="hideBox()" alt="Close" title="Close this Window" />
    <div id="title" style="color: #ff9933; font-weight: bold; font-size: 14px;">Tax Rate Properties</div><br />
    <div id="inner-box"></div>
</div>
	
<div class="kiwee-msc" id="mascot"><a href="http://www.kiweecommerce.org"><img src="actions/includes/Kiwee-small.gif" /></a></div>
<div class="subTitle"></div>
<div class="sectionHeader"><?php echo $_lang["kiwee_tax_header"]; ?></div>
<div class="sectionBody">
	<p><?php echo $_lang['kiwee_tax_desc']; ?></p>
<div>
<br />
	<form method="POST" action="">
		<label><?php echo $_lang['kiwee_tax_fld_postalcode']; ?>:&nbsp;</label><input id="postalcode" name="postalcode" type="text" length=20 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<label><?php echo $_lang['description']; ?>:&nbsp;</label><input id="description" name="description" type="text" length=50 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<label><?php echo $_lang['kiwee_tax_fld_rate']; ?>:&nbsp;</label><input id="rate" name="rate" type="text" length=10/>&nbsp;&nbsp;&nbsp;&nbsp;
		<button onclick="tax_add();"><?php echo $_lang['add']; ?></button>
		<br /><br />
  	</form>
	<div id="tax_grid" name="tax_grid" ></div>
</div>
